package bishi.didi;

import java.util.PriorityQueue;
import java.util.Scanner;

public class demo2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int s = in.nextInt();
        while(s > 0) {
            int n = in.nextInt();
            int[] arry = new int[n];
            for(int i = 0;i < n;i++) {
                arry[i] = in.nextInt();
            }
            //大根堆
            PriorityQueue<Integer> dmp = new PriorityQueue<>((x,y)->Integer.compare(y,x));
            for(int i = 1;i < n;i++) {
                dmp.offer(arry[i]);
            }
            int ret = 0;
            while(!dmp.isEmpty() && arry[0] <= dmp.peek()) {
                int max = dmp.poll();
                int x = max/2;
                arry[0] += x;
                dmp.offer(max - x);
                ret++;
            }
            System.out.println(ret);


            s--;
        }
    }
}
